<?php
require_once(dirname(__FILE__)."/../inc/common.php");
/*******************************************************************************************
'*******************************************************************************************/
if (newsparamset==0 || newsrunMode=="forgedStatic"){
    $paras = replaceStr(QUERY_STRING,fileSuffix,'');
    if (strpos($paras, "-") > 0) {
	    $parasArray = explode("-",$paras); $id = $parasArray[0]; $page = $parasArray[1];
    } else {
	    $id = $paras; $page = 1;
    }
} else {
	$id = getForm(newsparamid,"both") ; $page = getForm(newsparampage,"both");
}
if (empty($id)) {
	echoSaveStr("null");exit();
} else {
	if (is_numeric($id)){ $id = intval($id); } else { echoSaveStr("safe");exit();}
}
if (empty($page)) {
	$page=1;
} else {
	if (is_numeric($page)) { $page = intval($page); } else { echoSaveStr("safe");exit();}
}
echoChannel($id);

function echoChannel($typeId){
	global $page,$t1;
	$y = explode(",", getNewsTypeNameTemplateArrayOnCache($vType));$z = ifthen(empty($y[1]), "newspage.html", $y[1]);$x = DJCMS_TEMPLATE.$z;
	if (strpos(" ,".getHideNewsTypeIDS().",",",".$typeId.",") > 0) { OutNotFound("newspage");}
	$typeIds = getNewsTypeIdOnCache($typeId);
	djcms::$currentTypeId = $typeId;$cacheName = "parse_npl_".$typeId;
	if (cacheStart==1){
		if (!djcms::$content = memory('get', $cacheName)) {
            parseChannelPart($x,$y[0]);
            memory('set', $cacheName, djcms::$content);
        }
	} else {
		parseChannelPart($x,$y[0]);
	}
	djcms::$content = replaceStr(djcms::$content,"{newspagelist:page}",$page);
    djcms::parseNewsPartList($typeIds,$page,"newspage");
	djcms::parseIf();
	echo replaceStr(djcms::$content,"{yh:runinfo}",getRunTime($t1));
}

function parseChannelPart($x,$y)
{
	djcms::$content=loadFile($x);
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	$z = getTypeField(djcms::$currentTypeId,"m_keyword,m_description","news");
	$content = replaceStr(djcms::$content,"{yh:currenttypeid}", djcms::$currentTypeId);
	$content = replaceStr($content,"{newspagelist:typename}",$y);
	djcms::$content = replaceStr(replaceStr($content,"{newspagelist:keywords}",$z[0]),"{newspagelist:description}",$z[1]);
	djcms::parseMenuList("");
	djcms::parseNewsList();
	djcms::parseAreaList();
	djcms::parseVideoList();
	djcms::parseTopicList();
	djcms::$content = replaceStr(djcms::$content,"{newspagelist:typetext}", getNewsTypeTextOnCache(djcms::$currentTypeId));
}
?>
